<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class AnliController extends HomeController {

	//系统客户案例首页
    public function index()
    {
       $this->display("Anli/index");   
    }

    public function index_guanli()
    {   


        $model = M("Anlipic");
        // $list  = $model->select();
        
       //  echo "<pre>";
        // print_R($_SESSION);

     






        $uid = $_SESSION['home']['user_auth']['uid'];
        $count = $model->where(array('uid'=>$uid))->count();// 查询满足要求的总记录数
      // var_dump($arr);
        $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(10)
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $Page->setConfig('last','末页');
        $Page->setConfig('first','首页');
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出

         foreach($map1 as $key=>$val) {
            $Page->parameter[$key] = urlencode($val);
          }
      // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
          $data = $model->order('id')->where(array('uid'=>$uid))->limit($Page->firstRow.','.$Page->listRows)->select();
            // var_dump($data);
      
           $this->assign('page',$show);// 赋值分页输出

      // var_dump($arr);

             $this ->assign('data',$data);
     
             $this->display("Anli/index_guanli");
    }

     //添加案例Logo
   public function uploadPicture(){
        //TODO: 用户登录检测

        /* 返回标准数据 */
        $return  = array('status' => 1, 'info' => '上传成功', 'data' => '');

        /* 调用文件上传组件上传文件 */
        $Picture = D('Anlipic');
        $pic_driver = C('PICTURE_UPLOAD_DRIVER');
        $info = $Picture->upload(
            $_FILES,
            C('PICTURE_UPLOAD'),
            C('PICTURE_UPLOAD_DRIVER'),
            C("UPLOAD_{$pic_driver}_CONFIG")
        ); //TODO:上传到远程服务器

        /* 记录图片信息 */
        if($info){
            $return['status'] = 1;
            $return = array_merge($info['download'], $return);
        } else {
            $return['status'] = 0;
            $return['info']   = $Picture->getError();
        }

        /* 返回JSON数据 */
        $this->ajaxReturn($return);
    }



   //添加客户案例=。=  管理客户案例
   public function addAnli()
   {   
        
		
        $_POST['uid'] = $_SESSION['home']['user_auth']['uid'];
        $company      = M("Company");
        $id           = $_SESSION['Anli']['pic_id'];
        $cid          = $company->where("uid=".$_POST['uid'])->select();
        $_POST['cid'] = $cid[0]['id'];
       
        // echo "<pre>";
        // print_r($_POST);
        // print_R($_SESSION); 
        // die;
        
        $model        = M("Anlipic");
        $id_yz        = $model->where("id=".$id)->save($_POST);
        // print_R($id);
        // print_R($_SESSION);
        // var_dump($id_yz);
        // die;
        // echo "<pre>";
        // print_R($id_yz);
        // print_r($_POST);
        // print_R($_SESSION);
        // print_r($id_yz);
        // die; 
        if($id == null)
        {
           $this->display("Anli/index");
        }else{
          //显示客户添加的案例
            // $model = M("Anli");
            // $list  = $model->selelct();
            // print_r($list);
            // die;
         $model = M("Anlipic");
        // $list  = $model->select();
        
        // echo "<pre>";
        // print_R($_SESSION);

        $uid = $_SESSION['home']['user_auth']['uid'];
        $count = $model->where(array('uid'=>$uid))->count();// 查询满足要求的总记录数
      // var_dump($arr);
        $Page = new \Think\Page($count,8);// 实例化分页类 传入总记录数和每页显示的记录数(10)
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $Page->setConfig('last','末页');
        $Page->setConfig('first','首页');
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show = $Page->show();// 分页显示输出

         foreach($map1 as $key=>$val) {
            $Page->parameter[$key] = urlencode($val);
          }
      // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
          $data = $model->order('id')->where(array('uid'=>$uid))->limit($Page->firstRow.','.$Page->listRows)->select();
            // var_dump($data);
      
           $this->assign('page',$show);// 赋值分页输出

      // var_dump($arr);
          
             $this ->assign('data',$data);
     
             $this->display("Anli/index_guanli");
        }
        
   }

   //删除案例
   public function delanli()
   {
     // echo "<pre>";
     // print_r($_POST);
     $model = M("Anlipic");
     if($model->where($_POST)->delete() == false)
        {
           echo    false; 
        }else{
           echo   true;
            // echo 1;
        }
   }

   public function delete()
   {
   
    // print_R($_GET);
    // die;
    $id = $_GET['id'];
    $anli  = M("Anlipic");
    $anli->delete($id);
    $this->display("Anli/index_guanli");
   }


}